Skip to content

Conversation

bassgeta
Copy link
Contributor

@bassgeta bassgeta commented Oct 2, 2025

Problem

Even though we allow our users to pass their own payment reference via the API, I completely forgot to add that when initially developing the widget 🫠

Solution

Add the reference variable under the paymentConfig prop.

Changes

  • added reference app wide
  • onError -> onPaymentError
  • onSuccess -> onPaymentSuccess
  • new onComplete callback to fire when the modal is closed

Summary by CodeRabbit

  • New Features

    • Added optional paymentConfig.reference to tag payment requests.
    • Introduced onComplete callback, triggered when the widget closes after a successful payment.
    • Renamed callbacks: onSuccess → onPaymentSuccess and onError → onPaymentError.
  • Documentation

    • Updated README and examples to reflect new callback names, the onComplete hook, and the new reference field.
    • Refreshed homepage snippets (BasicPayment and PaymentWithWallet) to include paymentConfig.reference and the renamed event handlers.

@bassgeta bassgeta self-assigned this Oct 2, 2025
Copy link
Contributor

coderabbitai bot commented Oct 2, 2025

Walkthrough

Renamed PaymentWidget callbacks from onSuccess/onError to onPaymentSuccess/onPaymentError, added optional onComplete, and introduced paymentConfig.reference. Propagated these changes through types, context/provider, components, utils, examples, and documentation; included reference in API payout payloads.

Changes

Cohort / File(s) Change Summary
Example usage & wrapper
app/components/homepage.tsx, app/components/payment-widget-wrapper.tsx
Updated example and wrapper usages to add paymentConfig.reference and rename handlers to onPaymentSuccess / onPaymentError.
Public API & types
registry/default/payment-widget/payment-widget.types.ts, registry/default/payment-widget/payment-widget.tsx, public/r/payment-widget.json, registry/default/payment-widget/README.md
Added optional PaymentConfig.reference; renamed onSuccessonPaymentSuccess and onErroronPaymentError; introduced optional onComplete in public props and documentation.
Context & provider
registry/default/payment-widget/context/payment-widget-context/index.ts, .../payment-widget-provider.tsx, .../use-payment-widget-context.ts
Exposed paymentConfig.reference in context; replaced onSuccess/onError with onPaymentSuccess/onPaymentError; added onComplete in provider props and context value.
Widget components
registry/default/payment-widget/components/payment-modal.tsx, .../payment-confirmation.tsx, .../payment-success.tsx, .../connection-handler.tsx
Consumed renamed callbacks, forwarded reference into executePayment/payout flow, awaited/invoked onPaymentSuccess and invoked onComplete when closing from success; swapped onErroronPaymentError.
Payment flow utils & hooks
registry/default/payment-widget/utils/payment.ts, registry/default/payment-widget/hooks/use-payment.ts
Added optional reference to PaymentParams and included it in createPayout payload and executePayment params.
Registry metadata
public/r/payment-widget.json
Updated public manifest/types to reflect new reference field and renamed callbacks across widget/provider/context/components.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Widget as PaymentWidget
  participant Provider as PaymentWidgetProvider
  participant Modal as PaymentModal
  participant Confirm as PaymentConfirmation
  participant API as Backend API

  User->>Widget: open()
  Widget->>Provider: init(props: paymentConfig{reference?}, onPaymentSuccess?, onPaymentError?, onComplete?)
  Provider->>Modal: render

  User->>Modal: confirm payment
  Modal->>Confirm: prepare params (amount, recipient, reference?)
  Confirm->>API: executePayment(params with reference?)
  alt success
    API-->>Confirm: requestId, receipts
    Confirm->>Provider: await onPaymentSuccess?(requestId, receipts)
    User->>Modal: close success
    Modal->>Provider: onComplete?()
  else error
    API-->>Confirm: PaymentError
    Confirm->>Provider: onPaymentError?(PaymentError)
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • rodrigopavezi
  • MantisClone
  • aimensahnoun

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly describes the key changes by highlighting the addition of a new reference option and the cleanup of callback names, which aligns with the primary modifications in the PR.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/payment-reference

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c31d25f and 552027f.

📒 Files selected for processing (3)
  • public/r/payment-widget.json (7 hunks)
  • registry/default/payment-widget/hooks/use-payment.ts (1 hunks)
  • registry/default/payment-widget/utils/payment.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • registry/default/payment-widget/utils/payment.ts
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-09-17T12:08:58.198Z
Learnt from: bassgeta
PR: RequestNetwork/ui-registry#1
File: registry/default/payment-widget/components/payment-confirmation.tsx:31-41
Timestamp: 2025-09-17T12:08:58.198Z
Learning: In the payment widget context (registry/default/payment-widget/context/payment-widget-context.tsx), connectedWalletAddress is properly derived as `walletAccount?.account?.address || address` which handles both custom WalletClient scenarios and wagmi-managed wallets, so components should use connectedWalletAddress from context rather than address from usePayment hook.

Applied to files:

  • public/r/payment-widget.json
📚 Learning: 2025-09-17T12:08:58.198Z
Learnt from: bassgeta
PR: RequestNetwork/ui-registry#1
File: registry/default/payment-widget/components/payment-confirmation.tsx:31-41
Timestamp: 2025-09-17T12:08:58.198Z
Learning: In the payment widget context (registry/default/payment-widget/context/payment-widget-context.tsx), connectedWalletAddress is properly derived as `walletAccount ? walletAccount.account?.address : address` which handles both custom WalletClient scenarios and wagmi-managed wallets, so components should use connectedWalletAddress from context rather than address from usePayment hook.

Applied to files:

  • public/r/payment-widget.json
🔇 Additional comments (9)
registry/default/payment-widget/hooks/use-payment.ts (1)

103-103: LGTM: Reference field correctly propagated.

The reference field is appropriately threaded through the payment parameters to executePayment. The optional nature of the field is preserved, and the placement is consistent with other parameters.

public/r/payment-widget.json (8)

32-32: LGTM: Context types correctly updated.

The PaymentWidgetContextValue interface properly includes:

  • Optional reference field in paymentConfig
  • Renamed callbacks onPaymentSuccess and onPaymentError
  • New onComplete callback

All callback signatures are consistent with void | Promise<void> return types.


38-38: LGTM: Provider correctly implements new props and reference.

The PaymentWidgetProvider properly:

  • Accepts onPaymentSuccess, onPaymentError, and onComplete props
  • Threads paymentConfig.reference through the context value
  • Includes all new fields in the useMemo dependencies array

The implementation ensures correct re-rendering behavior when callbacks or reference change.


62-62: LGTM: Modal correctly invokes onComplete on close.

The PaymentModal properly:

  • Consumes onPaymentSuccess and onComplete from context
  • Invokes onComplete?.() when the user closes the modal from the success step
  • Uses conditional logic to ensure the callback only fires in the appropriate state

This provides a clean lifecycle hook for post-payment actions.


80-80: LGTM: Payment confirmation properly handles reference and renamed callbacks.

The PaymentConfirmation component correctly:

  • Extracts reference from paymentConfig context
  • Passes reference to executePayment in the payment params
  • Uses the renamed onPaymentError callback in error handling

The implementation ensures the reference is propagated through the payment execution flow.


98-98: LGTM: Type definitions correctly updated.

The payment-widget.types.ts properly defines:

  • Optional reference?: string in PaymentConfig
  • Renamed callbacks onPaymentSuccess and onPaymentError in PaymentWidgetProps
  • New onComplete callback in PaymentWidgetProps

All type signatures are consistent with the implementation across other files.


116-116: LGTM: Payment utility correctly includes reference in API calls.

The utils/payment.ts properly:

  • Adds optional reference?: string to PaymentParams interface
  • Extracts reference from params in createPayout
  • Includes reference in the API request body sent to /v2/payouts

The implementation ensures the reference is transmitted to the Request Network API.


140-140: Note: Duplicate entry for use-payment hook.

This content duplicates the changes already reviewed in registry/default/payment-widget/hooks/use-payment.ts. The reference field propagation is correct.


176-176: LGTM: Documentation comprehensively covers new features.

The README properly documents:

  • The new onComplete callback with clear usage examples
  • The optional reference field in PaymentConfig with practical examples
  • The renamed callbacks onPaymentSuccess and onPaymentError throughout all code samples

The documentation provides clear guidance on when and how to use these new features.


Comment @coderabbitai help to get the list of available commands and usage tips.

@bassgeta bassgeta force-pushed the fix/payment-reference branch from 6836c1e to c31d25f Compare October 2, 2025 14:14
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
registry/default/payment-widget/payment-widget.tsx (1)

87-97: Pass onComplete to the provider.

The onComplete callback is defined in PaymentWidgetProps but is not destructured from props or passed to PaymentWidgetProvider. This means the callback will never fire even if a consumer provides it.

Apply this diff to fix the issue:

 export function PaymentWidget({
   amountInUsd,
   recipientWallet,
   paymentConfig,
   receiptInfo,
   onPaymentSuccess,
   onPaymentError,
+  onComplete,
   uiConfig,
   walletAccount,
   children,
 }: PaymentWidgetProps) {
   return (
     <Web3Provider walletConnectProjectId={paymentConfig.walletConnectProjectId}>
       <PaymentWidgetProvider
         amountInUsd={amountInUsd}
         recipientWallet={recipientWallet}
         walletAccount={walletAccount}
         paymentConfig={paymentConfig}
         uiConfig={uiConfig}
         receiptInfo={receiptInfo}
         onPaymentSuccess={onPaymentSuccess}
         onPaymentError={onPaymentError}
+        onComplete={onComplete}
       >
         <PaymentWidgetInner>{children}</PaymentWidgetInner>
       </PaymentWidgetProvider>
     </Web3Provider>
   );
 }
🧹 Nitpick comments (1)
registry/default/payment-widget/payment-widget.types.ts (1)

69-70: Clarify the onComplete callback timing.

The comment states "Callback when the widget is closed from the success step", but based on the implementation in payment-modal.tsx (lines 79-86), this callback fires when the modal closes from the success step. Consider clarifying whether this fires only on user-initiated close or also programmatic close.

Apply this diff to improve the comment:

-  // Callback when the widget is closed from the success step
+  // Callback invoked when the modal is closed after reaching the payment success step
   onComplete?: () => void | Promise<void>;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b8d2b9b and c31d25f.

📒 Files selected for processing (11)
  • app/components/homepage.tsx (4 hunks)
  • app/components/payment-widget-wrapper.tsx (1 hunks)
  • public/r/payment-widget.json (6 hunks)
  • registry/default/payment-widget/README.md (5 hunks)
  • registry/default/payment-widget/components/payment-confirmation.tsx (3 hunks)
  • registry/default/payment-widget/components/payment-modal.tsx (3 hunks)
  • registry/default/payment-widget/context/payment-widget-context/index.ts (2 hunks)
  • registry/default/payment-widget/context/payment-widget-context/payment-widget-provider.tsx (5 hunks)
  • registry/default/payment-widget/payment-widget.tsx (2 hunks)
  • registry/default/payment-widget/payment-widget.types.ts (2 hunks)
  • registry/default/payment-widget/utils/payment.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
registry/default/payment-widget/payment-widget.types.ts (1)
registry/default/payment-widget/types/index.ts (1)
  • PaymentError (8-11)
registry/default/payment-widget/context/payment-widget-context/index.ts (1)
registry/default/payment-widget/types/index.ts (1)
  • PaymentError (8-11)
registry/default/payment-widget/context/payment-widget-context/payment-widget-provider.tsx (1)
registry/default/payment-widget/types/index.ts (1)
  • PaymentError (8-11)
🔇 Additional comments (33)
registry/default/payment-widget/payment-widget.types.ts (2)

8-8: LGTM! Optional reference field added correctly.

The addition of the optional reference field to PaymentConfig allows consumers to pass custom payment references while maintaining backward compatibility.


63-68: LGTM! Callback renames improve API clarity.

Renaming onSuccessonPaymentSuccess and onErroronPaymentError makes the API more explicit and aligns with the introduction of the new onComplete lifecycle callback.

registry/default/payment-widget/context/payment-widget-context/index.ts (2)

14-14: LGTM! Reference field added to context.

The optional reference field is correctly added to the context's paymentConfig, maintaining consistency with the public API.


27-32: LGTM! Context callbacks updated correctly.

The context value type correctly reflects the renamed callbacks (onPaymentSuccess, onPaymentError) and the new onComplete lifecycle hook, maintaining signature compatibility.

registry/default/payment-widget/context/payment-widget-context/payment-widget-provider.tsx (4)

21-26: LGTM! Provider props updated correctly.

The provider interface correctly reflects the renamed callbacks and maintains backward compatibility by keeping all callbacks optional.


56-56: LGTM! Reference field threaded through context.

The reference field from paymentConfig is correctly extracted and included in the context value, enabling downstream components to access it.


66-68: LGTM! Callbacks properly wired through context.

The renamed callbacks (onPaymentSuccess, onPaymentError) and new onComplete callback are correctly included in the context value.


79-85: LGTM! Dependency array correctly updated.

All new and renamed props (paymentConfig.reference, onPaymentSuccess, onPaymentError, onComplete) are correctly added to the useMemo dependency array, preventing stale closures.

registry/default/payment-widget/utils/payment.ts (2)

10-10: LGTM! Reference parameter added correctly.

The optional reference field is properly added to PaymentParams, maintaining consistency with the interface design pattern used for other optional fields.


147-147: LGTM! Reference forwarded to API.

The reference field is correctly included in the payout API request payload, enabling the backend to associate payments with custom references.

registry/default/payment-widget/payment-widget.tsx (1)

92-93: LGTM! Callback props renamed correctly.

The destructured props correctly use the new callback names onPaymentSuccess and onPaymentError, maintaining consistency with the type definitions.

registry/default/payment-widget/components/payment-confirmation.tsx (3)

35-35: LGTM! Reference extracted from context.

The reference field is correctly destructured from paymentConfig in the context, making it available for the payment flow.


61-61: LGTM! Reference included in payment payload.

The reference is correctly passed to executePayment, ensuring it's included in the API request to associate the payment with the custom reference.


37-37: LGTM! Error callback correctly updated.

The error handling correctly uses the renamed onPaymentError callback from the context (line 37) and invokes it appropriately (line 101).

Also applies to: 101-101

app/components/payment-widget-wrapper.tsx (1)

82-83: LGTM! Wrapper updated with renamed callbacks.

The wrapper correctly uses the renamed callback props onPaymentSuccess and onPaymentError, maintaining consistency with the updated public API.

registry/default/payment-widget/components/payment-modal.tsx (3)

30-31: LGTM! Modal uses renamed callbacks from context.

The modal correctly destructures onPaymentSuccess and onComplete from the context, enabling the new lifecycle hooks.


57-67: LGTM! Payment success handler awaits callback.

The onPaymentSuccess callback is correctly awaited, allowing consumers to perform async operations (e.g., analytics, logging) before the UI transitions to the success state.


79-86: LGTM! onComplete fires on modal close from success.

The onComplete callback is correctly invoked when the modal closes from the payment success step, providing consumers with a lifecycle hook to react to payment completion and modal dismissal.

app/components/homepage.tsx (4)

58-58: LGTM: Reference field correctly added.

The reference field is properly placed in paymentConfig with an appropriate placeholder value for documentation purposes.


84-89: LGTM: Callback props correctly renamed.

The callback props have been renamed from onSuccess/onError to onPaymentSuccess/onPaymentError, maintaining the correct signatures and usage.


108-109: LGTM: Reference field consistently added.

The reference field is correctly added to the PaymentWithWallet example, maintaining consistency with the BasicPayment example.


138-143: LGTM: Callbacks consistently renamed.

The callback props are correctly renamed to onPaymentSuccess/onPaymentError, maintaining consistency with the BasicPayment example and the updated API.

registry/default/payment-widget/README.md (5)

77-78: LGTM: Basic usage example correctly updated.

The callbacks in the basic usage example correctly demonstrate the renamed onPaymentSuccess and onPaymentError props with appropriate parameters.


215-221: LGTM: Event handlers correctly documented.

The event handlers section properly documents onPaymentSuccess and onPaymentError with accurate signatures and descriptions.


237-264: LGTM: New features well documented.

The new onComplete callback and PaymentConfig.reference field are clearly documented with appropriate examples and descriptions that explain their purpose and usage.


312-313: LGTM: Wagmi example correctly updated.

The Wagmi example correctly uses the renamed callback props, maintaining consistency with other documentation examples.


365-365: LGTM: Error handling section correctly updated.

The reference to the error callback has been properly updated to use onPaymentError.

public/r/payment-widget.json (6)

98-98: LGTM: Type definitions correctly updated.

The PaymentWidgetProps and PaymentConfig types correctly reflect the API changes:

  • reference field added as optional string
  • Callbacks renamed to onPaymentSuccess and onPaymentError with correct signatures
  • New onComplete callback added

32-32: LGTM: Context types correctly updated.

The PaymentWidgetContextValue interface properly includes the reference field in paymentConfig and all three callback props with correct signatures.


38-38: LGTM: Provider correctly propagates new props.

The PaymentWidgetProvider properly:

  • Accepts and destructures the new callback props and reference field
  • Includes reference in the context's paymentConfig object
  • Adds all new fields to the useMemo dependency array

62-62: LGTM: PaymentModal correctly handles callbacks.

The PaymentModal component properly:

  • Retrieves onPaymentSuccess and onComplete from context
  • Calls onPaymentSuccess when payment succeeds
  • Calls onComplete when the modal is closed from the success step

80-80: LGTM: PaymentConfirmation correctly uses reference and callbacks.

The PaymentConfirmation component properly:

  • Extracts reference from paymentConfig via context
  • Passes reference to the payment execution flow
  • Uses onPaymentError for error handling

116-116: LGTM: Payment utils correctly handle reference field.

The PaymentParams interface includes the optional reference field, and the createPayout function properly includes it in the API request payload sent to the backend.

Copy link
Member

@rodrigopavezi rodrigopavezi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Review Report

Overview

This PR introduces several enhancements to the Payment Widget component, focusing on improved callback naming consistency, payment reference tracking, and post-payment flow handling.

Summary of Changes

🔄 Callback Prop Renaming

  • Changed: onSuccessonPaymentSuccess
  • Changed: onErroronPaymentError
  • Impact: Improves API clarity and consistency across the component

New Features

1. Payment Reference Tracking

  • Added: reference?: string field to PaymentConfig interface
  • Purpose: Allows associating custom tracking identifiers with payment requests
  • Usage: Optional field for internal payment tracking and reconciliation

2. Post-Payment Completion Callback

  • Added: onComplete?: () => void | Promise<void> prop
  • Purpose: Handles cleanup or navigation after payment flow completion
  • Trigger: Called when user closes the payment widget from the success screen

Detailed Changes by File

Type Definitions (payment-widget.types.ts)

// Added to PaymentConfig
reference?: string;

// Renamed in PaymentWidgetProps
onPaymentSuccess?: (requestId: string, receipts: TransactionReceipt[]) => void | Promise<void>;
onPaymentError?: (error: PaymentError) => void | Promise<void>;

// Added to PaymentWidgetProps
onComplete?: () => void | Promise<void>;

Context Layer Updates

  • Context Interface: Updated to include new reference and onComplete properties
  • Provider: Properly passes through all new props to context consumers
  • Hook: Maintains backward compatibility while exposing new functionality

Payment Logic (utils/payment.ts)

  • PaymentParams Interface: Added reference?: string field
  • API Integration: Reference field properly included in payout creation request
  • Backward Compatibility: Reference field is optional, maintaining existing integrations

Payment Execution (hooks/use-payment.ts)

  • Parameter Passing: Reference field correctly propagated through payment execution chain
  • Type Safety: All type definitions updated consistently

UI Components

  • Payment Modal: Integrated onComplete callback with modal close handling
  • Success Flow: Proper callback invocation when user completes payment flow

Documentation (README.md)

  • Updated Examples: All code examples use new callback names
  • New Props Documentation: Comprehensive documentation for reference and onComplete props
  • Migration Guide: Clear guidance on new prop usage

Code Quality Assessment

Strengths

  1. Consistent Naming: The renaming from onSuccess/onError to onPaymentSuccess/onPaymentError provides better semantic clarity
  2. Type Safety: All changes maintain strict TypeScript typing
  3. Backward Compatibility: New features are optional and don't break existing implementations
  4. Comprehensive Updates: Changes are consistently applied across all layers (types, context, hooks, components)
  5. Documentation: README thoroughly updated with examples and usage guidance

Implementation Quality

  1. Proper Context Flow: New props correctly flow through the context system
  2. Optional Fields: All new features are optional, maintaining API stability
  3. Error Handling: Existing error handling patterns preserved
  4. Clean Integration: Reference field cleanly integrated into payment API calls

Testing Considerations

Verified Functionality

  • Type definitions are consistent across all files
  • Context properly propagates new props
  • Payment API correctly includes reference field
  • Modal properly handles completion callback

🔍 Recommended Testing

  1. Integration Tests: Verify onComplete callback fires correctly on modal close from success state
  2. API Tests: Confirm reference field is properly sent to Request Network API
  3. Backward Compatibility: Ensure existing implementations without new props continue working
  4. Type Checking: Verify TypeScript compilation with both old and new prop patterns

Migration Impact

🟢 Low Risk Changes

  • All new features are optional
  • Existing implementations will continue working without modification
  • No breaking changes to core functionality

📝 Developer Migration

Developers can optionally update their implementations:

// Before
<PaymentWidget
  onSuccess={(requestId) => console.log('Success:', requestId)}
  onError={(error) => console.error('Error:', error)}
/>

// After (optional migration)
<PaymentWidget
  onPaymentSuccess={(requestId, receipts) => console.log('Success:', requestId, receipts)}
  onPaymentError={(error) => console.error('Error:', error)}
  onComplete={() => console.log('Payment flow completed')}
  paymentConfig={{
    // ... other config
    reference: "invoice-12345" // Optional tracking reference
  }}
/>

Recommendations

Approve

This PR is well-implemented and ready for merge:

  1. Clean Implementation: All changes are consistently applied across the codebase
  2. Maintains Compatibility: No breaking changes for existing users
  3. Adds Value: New features provide useful functionality for payment tracking and flow management
  4. Good Documentation: README properly updated with examples and guidance
  5. Type Safety: All TypeScript definitions are properly maintained

🔧 Minor Suggestions

  1. Consider adding JSDoc comments to new interface properties for better IDE support
  2. Could add validation for reference field length/format if API has constraints

Conclusion

This is a solid enhancement PR that improves the Payment Widget's API consistency and adds valuable new features. The implementation is clean, well-documented, and maintains backward compatibility. The changes follow good software engineering practices and are ready for production use.

Recommendation: ✅ APPROVE AND MERGE

@bassgeta bassgeta merged commit 30f1efc into main Oct 7, 2025
1 check passed
@bassgeta bassgeta deleted the fix/payment-reference branch October 7, 2025 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants